<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" placeholder="请输入1-100之间的整数" id="i1">
<input type="button" value="猜一猜" onclick="fn()">
<div></div>
<script>
    //得到一个1-100之间的随机整数
    let x = parseInt(Math.random()*100)+1;
    //统计次数的变量
    let count = 0;
    function fn() {
        count++;
        let i = document.querySelector("#i1");
        let d = document.querySelector("div");
        if (i.value>x){
            d.innerText="猜大了!";
        }else if(i.value<x){
            d.innerText="猜小了!";
        }else{
            d.innerText="恭喜你第"+count+"次猜对了!";
        }
    }

</script>

</body>
</html>